package controllayer;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class PersonCtrlTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class PersonCtrlTest
{
    /**
     * Default constructor for test class PersonCtrlTest
     */
    public PersonCtrlTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {

    }

    @Test
    public void testCreatePerson()
    {
        controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        assertEquals("Person created", personCt1.createPerson("Lasse", "Tranumvej 118", "9440", "Aabybro", "28494531"));
        assertEquals("There is already a person with that number!", personCt1.createPerson("Lasse", "Tranumvej 118", "9440", "Aabybro", "28494531"));
        personCt1.deletePerson("28494531");
    }

    @Test
    public void findPerson()
    {
        controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        personCt1.createPerson("Lasse", "Tranumvej 118", "9440", "Aabybro", "28494531");
        assertNotNull(personCt1.findPerson("28494531"));
        assertNull(personCt1.findPerson("12345678"));
        personCt1.deletePerson("28494531");
    }

    @Test
    public void editPerson()
    {
        controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        personCt1.createPerson("Lasse", "Tranumvej 118", "9440", "Aabybro", "123");
        assertEquals(true, personCt1.editPerson("123","Lasse", "Tranumvej 118", "9440", "Aabybro", "28494531"));
        assertEquals(false, personCt1.editPerson("123","Lasse", "Tranumvej 118", "9440", "Aabybro", "28494531"));
        personCt1.deletePerson("28494531");
    }
    
    @Test
    public void testDeletePerson()
    {
        controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        personCt1.createPerson("Lasse", "Tranumvej 118", "9440", "Aabybro", "28494531");
        assertEquals(false, personCt1.deletePerson("123456789"));
        assertEquals(true, personCt1.deletePerson("28494531"));
    }
}


